package com.learn.practice.pojo;

import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;

@Data
public class LoginUser implements UserDetails {
    //(3)权限信息，这里需要注意的是要禁止序列化，不然存储到缓存中会有问题
    private List<GrantedAuthority> authorities;

    private String userName;
    private String password;
    private String phone;

    public LoginUser(String userName, String password){
        this.userName = userName;
        this.password = password;
    }

    public LoginUser(String userName, String password, List<GrantedAuthority> authorities){
        this.userName = userName;
        this.password = password;
        this.authorities = authorities;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public String getPassword() {
        return password;
    }

    @Override
    public String getUsername() {
        return userName;
    }

    @Override
    public boolean isAccountNonExpired() {
        //账号是否过期，因为用户表里面没有这个字段，因此默认账号不过期，下面几个方法同理
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}